<?php
class AutenticacaoController extends AppController{

    public function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->allow('login', 'logout');

    }

    public function index() {
        $this->Autenticacao->recursive = 1;
        $this->set('Autenticacao', $this->paginate());
    }
    
    public function view($id = null) {
        $this->Autenticacao->id = $id;
        if (!$this->Autenticacao->exists()) {
            throw new NotFoundException(__('Usuário inválido'));
        }
        $this->set('Autenticacao', $this->Autenticacao->read(null, $id));
    }

    public function login() {

        $this->Session->destroy();
        if($this->request->is('post')){    
            //print_r($this->request->data);exit;
            if ($this->Auth->login()) {
                $this->Session->write('UsuarioLogado', $this->Auth->user());
                $this->redirect('/Chamado/');
                //return $this->redirect($this->Auth->redirect());
            } else {
                $this->Session->write('msg_erro', 'Email ou senha inválidos');
            }
        }

    }




    public function logout() {
        $this->Session->destroy();
        $this->redirect('/');
        //$this->redirect($this->Auth->logout());
    }

}

?>